package cn.gov.anhai.controller;

import cn.gov.anhai.service.FolkloreIntangibleHeritageService;
import cn.gov.anhai.service.RuralCulturalTourismService;
import cn.gov.anhai.utils.ApiResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping(value = "/folkloreIntangibleHeritage")
@Api(tags = {"民俗非遗"})
public class FolkloreIntangibleHeritageController {
    private Logger logger = LoggerFactory.getLogger(FolkloreIntangibleHeritageController.class);

    @Resource
    FolkloreIntangibleHeritageService folkloreIntangibleHeritageService;

    /**
     * 民俗非遗列表
     */
    @GetMapping(value = "/list")
    @ApiOperation(value = "民俗非遗列表")
    public ApiResult<Object> bannerList(Integer current, Integer size, HttpServletRequest request) throws Exception {
        Map<String, Object> result = new HashMap<>();
        List<Map<String, Object>> records = folkloreIntangibleHeritageService.list(current, size);
        Integer total = folkloreIntangibleHeritageService.listCount();
        result.put("records", records);
        result.put("total", total);
        return ApiResult.ok(result);
    }

    /**
     * 民俗非遗详情
     */
    @GetMapping(value = "/{id}")
    @ApiOperation(value = "民俗非遗详情")
    public ApiResult<Object> bannerList(@PathVariable("id") Long id, HttpServletRequest request) throws Exception {
        Map<String, Object> info = folkloreIntangibleHeritageService.info(id);
        if (info == null) return ApiResult.fail("查无信息");
        return ApiResult.ok(info);
    }

    /**
     * 民俗非遗背景
     */
    @GetMapping(value = "/back")
    @ApiOperation(value = "民俗非遗背景")
    public ApiResult<Object> back(HttpServletRequest request) throws Exception {
        String data = folkloreIntangibleHeritageService.back();
        return ApiResult.ok("获取成功", data);
    }

}
